﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace NFlickr.Core
{
    public class User
    {
        internal User()
        {

        }
        public string UserId
        {
            get;
            set;
        }
        public string UserName
        {
            get;
            set;
        }
        public string FullName
        {
            get;
            set;
        }

        public static bool TryParse(string text, out User user)
        {
            XDocument document = XDocument.Parse(text);
            User result = null;
            XElement rspElement = document.Element("rsp");
            if (rspElement.Attribute("stat").Value.Equals("ok"))
            {
                XElement userElement = rspElement.Element("auth").Element("user");
                result = new User { FullName = userElement.Attribute("fullname").Value, UserId = userElement.Attribute("nsid").Value, UserName = userElement.Attribute("username").Value };
                user = result;
                return true;

            }
            else
            {
                user = null;
                return false;


            }
        }
    }
}
